package com.hdoit.kylin.logical.groupActivity.dao.impl;

import java.util.List;

import org.springframework.stereotype.Component;

import com.tennetcn.common.dao.base.IFinderExpression;
import com.tennetcn.common.dao.base.impl.SuperDao;
import com.tennetcn.common.enums.OrderEnum;
import com.tennetcn.common.logical.superbase.model.Employee;
import com.tennetcn.common.message.PagerModel;
import com.tennetcn.common.utils.FinderExpressionFactory;
import com.hdoit.kylin.logical.groupActivity.dao.IGroupDutyDao;
import com.hdoit.kylin.logical.groupActivity.model.GroupDuty;
import com.hdoit.kylin.logical.viewmodel.groupActivity.GroupDutySearch;
/**
 * @author      guoshuren
 * @email       
 * @createtime  2018年03月07日 16:15:41
 * @comment
 */
@Component
public class GroupDutyDaoImpl extends SuperDao<GroupDuty> implements IGroupDutyDao{

	@Override
	public List<GroupDuty> queryList(GroupDutySearch search,
			PagerModel pagerModel) {
		IFinderExpression finderExpression = FinderExpressionFactory.createExpression();
		finderExpression.select("groupDuty.*","employee.employeeName as employeeName")
						.from(GroupDuty.class,"groupDuty")
						.leftJoin(Employee.class,"employee")
						.on("groupDuty.employeeId","employee.employeeId")
						.addOrder("groupDuty.weekDate", OrderEnum.asc);
		this.append(search,finderExpression);
		
		if(pagerModel == null){
			return queryList(finderExpression,search);
		}
		
		return queryList(finderExpression,search,pagerModel);
	}

	private void append(GroupDutySearch search,
			IFinderExpression finderExpression) {
		
		if(search.getGroupId()!=null){
			finderExpression.andWhere("groupDuty.groupId = #{groupId}")
							.setParam("groupId", search.getGroupId());
		}
		if(search.getTermId() != null){
			finderExpression.andWhere("groupDuty.termId = #{termId}")
							.setParam("termId", search.getTermId());
		}
	}

}